﻿#!/usr/bin/perl
use LWP::UserAgent;
use HTTP::Request::Common qw(GET);
use URI;

use constant MAINPAGE => 'http://www.example.com/search.asp';

$UA   = LWP::UserAgent->new();
$req = HTTP::Request->new( GET => MAINPAGE );

# Ta tablica ustawia parametr rozmiaru testowanych danych na 8 bitów, 16 bitów i 32 bity
my @testSizes = ( 8, 16, 32 );

foreach $numBits (@testSizes) {
    my @boundaryValues = (
        ( 2**( $numBits - 1 ) - 1 ),
        ( 2**( $numBits - 1 ) ),
        ( 2**( $numBits - 1 ) +1 ),
        ( 2**$numBits - 1 ),
        ( 2**$numBits ),
        ( 2**$numBits + 1 ),
    );
    foreach $testValue (@boundaryValues) {
        my $url = URI->new(MAINPAGE);
        $url->query_form(
            'term' => 'Mac',
            'max'  => $testValue
        );

        # Pobieranie stron wewnątrz pętli. W każdej
        # iteracji przyjmujemy inną wartość parametru.
        $req->uri($url);
        $resp = $UA->request($req);

        # Wyświetlenie komunikatów o ewentualnych błędach.
        if ( ( $resp->code() < 200 ) || ( $resp->code() >= 400 ) ) {
            print resp->status_line . $req=>as_string();
        }
    }
}
